/**
 * Created by Administrator on 2016/6/13.
 */
$(document).ready(function(){
    var str = window.location.search;
    var order_no = str.replace(/[^0-9]+/g, '');
    var user_token =  sessionStorage.user_token;
    $(".dairyInfoGroup>span").text("咨询编号："+order_no);
    var book_id = sessionStorage.book_id;
    var u_id =sessionStorage.u_id;
    var page = '';
    $.post(commonval+"/note_list", {
        user_token:user_token,
        device:"wap",
        u_id : u_id,
        book_id:book_id,
        page:page
    }, function (data) {
        console.log(data.data == '');
        if(data.status == 0){
            createWindow("获取生发日记列表失败");
        }else{
            if(data.data == ''){
                $(".dairyInfoGroup").css("display","none");
                $("#mainPart").css("display","none");
                createWindow("您暂时还没有日记");
            }else{
                $(".dairyInfoGroup").css("display","inherit");
                $("#mainPart").css("display","block");
                var dairyBook = new Vue({
                    el: '#mainPart',
                    data: {
                        items: data.data
                    }
                });
                var doc_name = data.data[0].doctor_name;
                var order_num = data.data[0].order_num;
                var d_id = data.data[0].d_id;
                $(".dairyInfoGroup a span").text(doc_name);
                $(".dairyInfoGroup a").click(function(){
                    location.href="doctorInfo.html?d_id="+d_id;
                })
                $("header img:last-child").click(function(){
                    location.href="writeDairy.html?order_num="+order_num;
                })
                //渲染图片逻辑
                var dataUse = data.data;
                for(var i=0;i<dataUse.length;i++){
                    var content_image = dataUse[i].content_image;
                    for(var j=0;j<content_image.length;j++){
                        var href = content_image[j];
                        var img = $("<img>" );
                        //img.attr("src",href);

                        //
                        //var href = "http://dev.haotoufa.com"+content_image[j];
                        //var img = $("<img>" );
                        var z = j+1;
                        var alt = z+"/"+content_image.length;
                        img.attr("src",href);
                        img.attr("alt",alt);
                        var a = $("<a href='#'></a>");
                        a.attr("href",href);
                        var li = $("<li></li>");
                        img.appendTo(a);
                        a.appendTo(li);
                        //li.appendTo($(".dairyDetailGroup").eq(i).children(".imgGroup"));
                        li.insertBefore($(".dairyDetailGroup").eq(i).children(".imgGroup").children("p"));
                        $(".dairyDetailGroup").eq(i).children(".imgGroup").parent().attr("id","Gallery"+i);
                    }
                }
            }
        }
    });
});




